#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int g_unval;     
int g_val = 100; 
int main(int argc, char* argv[], char* env[])
{
	const char* str = "helloworld";
	printf("code addr: %p\n", main);              //正文代码区
	printf("init global addr: %p\n", &g_val);     //未初始化数据区
	printf("uninit global addr: %p\n", &g_unval); //初始化数据区

	static int test = 10;
	char* heap_mem = (char*)malloc(10);
	char* heap_mem1 = (char*)malloc(10);
	char* heap_mem2 = (char*)malloc(10);
	char* heap_mem3 = (char*)malloc(10);

	// 堆区
	printf("heap addr: %p\n", heap_mem); 
	printf("heap addr: %p\n", heap_mem1); 
	printf("heap addr: %p\n", heap_mem2); 
	printf("heap addr: %p\n", heap_mem3); 

	//栈区
	printf("test  addr: %p\n", &test); 
	printf("stack addr: %p\n", &heap_mem); 
	printf("stack addr: %p\n", &heap_mem1); 
	printf("stack addr: %p\n", &heap_mem2); 
	printf("stack addr: %p\n", &heap_mem3); 

    //字符串常量
    printf("read only string addr: %p\n", str);

    //命令行参数
    for(int i = 0 ;i < argc; i++)
    {
        printf("argv[%d]: %p\n", i, argv[i]);
    }

    //环境变量
    for(int i = 0; env[i]; i++)
    {
        printf("env[%d]: %p\n", i, env[i]);
    }
 
	return 0;
}
